Skip to content

Mitigate exception thrown on returningBroken connection to the pool#4519

Closed
ggivo wants to merge 1 commit into
masterfrom
topic/ggivo/commons-pool-454-mitigate-exception-on-invalidate
Closed

Mitigate exception thrown on returningBroken connection to the pool#4519
ggivo wants to merge 1 commit into
masterfrom
topic/ggivo/commons-pool-454-mitigate-exception-on-invalidate

Conversation

@ggivo

@ggivo ggivo commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Mitigate POOL-431 regression: returnBrokenResource throws when upstream is down

A behavioral regression was introduced in commons-pool 2.13.0 as part of the fix for POOL-424: GenericObjectPool#invalidateObject now unconditionally replaces the destroyed instance by internally calling addObject(). When the upstream Redis is unreachable, the implicit replacement fails and the exception propagates out of Jedis#close() / pool.returnBrokenResource(...), breaking the pre-2.13 contract where returning a broken connection was a silent no-op on the failure path. This is tracked upstream as POOL-431.

Related PR's:

This change moves the mitigation down to Pool<T> so every Jedis pool benefits. A thread-local guard set across returnBrokenResource(...) lets an addObject() override swallow failures originating from the implicit auto-replace


Note

Medium Risk
Touches core connection pooling behavior by changing how broken resources are invalidated under commons-pool2 2.13.x; mistakes could hide real pool/factory failures or affect pool liveness under load.

Overview
Restores pre-commons-pool2-2.13 behavior where closing/returning a broken Jedis resource does not throw if Redis is down, by adding a thread-local guard in Pool.returnBrokenResource and overriding addObject() to suppress only the implicit auto-replacement failure triggered by invalidateObject().

Upgrades commons-pool2 to 2.13.1 and adds coverage: a new PoolUnitTest for suppression/propagation semantics, plus an updated UnavailableConnectionTest that uses Toxiproxy (new redis-unavailable endpoint + docker-compose port) to reliably simulate an unreachable Redis instance.

Reviewed by Cursor Bugbot for commit 62d001f. Bugbot is set up for automated code reviews on this repo. Configure here.

A behavioral regression was introduced in commons-pool 2.13.0 as part of the fix for POOL-424, which ensures that invalidateObject() replaces the destroyed instance by internally calling addObject(). This leads to exception being propagated in case new Jedis/Connection can not be established.

This commit introduce a mitigation code to allow Jedis to wotk with 2.13.1  till apache/commons-pool#454 is resolved
@jit-ci

jit-ci Bot commented May 8, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

Test Results

  191 files  ±0    191 suites  ±0   9m 29s ⏱️ +5s
7 569 tests ±0  7 198 ✅ +1  371 💤  - 1  0 ❌ ±0 
7 577 runs  ±0  7 198 ✅ +1  379 💤  - 1  0 ❌ ±0 

Results for commit 62d001f. ± Comparison against base commit b2228fc.

♻️ This comment has been updated with latest results.

@ggivo ggivo requested review from atakavci and uglide and removed request for uglide May 11, 2026 06:44
@ggivo

ggivo commented May 11, 2026

Copy link
Copy Markdown
Collaborator Author

Discussed with the team and decided it introduces risks of future incompatibility with the library. Closing in favour of
#4439

@ggivo ggivo closed this May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant